/* eslint-disable react/forbid-prop-types */
import React from 'react';
import {useCreation, usePersistFn} from 'ahooks';
// omit的作用是过滤不想传递的一些属性
import omit from 'omit.js';
import PropTypes from 'prop-types';
// 顶部查询表单比较常用，封装一个通用组件
import StandardForm from '@/components/StandardForm';
import {FItemProps} from '@/components/FormComponents/interface';

const SearchForm = props => {
    const {onFinish} = props;

    const formItems = useCreation(() => [
        {
            label: '辅导老师',
            key: 'teacher',
            type: 'input',
            props: {
                placeholder: '请输入老师姓名'
            }
        },
        {
            label: '日期',
            key: 'date',
            type: 'datePicker',
            props: {
                format: 'YYYY-MM-DD'
            }
        },
    ], []) as FItemProps[];

    const handleFinish = usePersistFn((params = {}) => {
        const payload = {...params};
        // 时间类型单独处理
        if (params?.date) {
            payload.date = params.date.valueOf();
        }
        onFinish(payload);
    });

    return (
        <StandardForm
            formItems={formItems}
            onFinish={handleFinish}
            // 过滤掉三个属性，其余透传给组件
            {...omit(props, ['onFinish', 'departmentList', 'gradeList'])}
        />
    );
};

SearchForm.propTypes = {
    onFinish: PropTypes.func.isRequired,
    onReset: PropTypes.func.isRequired,
    loading: PropTypes.bool.isRequired,
};

export default SearchForm;
